<template>
  <div class="oset">
    <!-- 按钮权限 -->
    <!-- {{$refs.tree.getCheckedKeys()}} -->
    <el-tree
    class="eltree"
      :data="T_data"
      show-checkbox
      node-key="id"
      ref="tree"
      :default-checked-keys="C_arr_data"
      :props="defaultPropsLeft"
      @node-click="NodeClick"
      @check-change="checkChange"
    ></el-tree>
  </div>
</template>
<script>
import {elementEcho} from '@/api/tenantRolePermissions'
export default {
  props: ["CheckedBtnArr", "rowClone", "pc", "TreeSaveNode"],
  data() {
    return {
      //选中的
      C_arr_data: [],
      checkChangeData:[],
    //   C3:this.$refs.tree.getCheckedKeys(),
      //数据
      T_data: [],
      //属性
      defaultPropsLeft: {
        children: "children",
        label: "name"
      }
    };
  },
  mounted() {
    this.T_data = JSON.parse(JSON.stringify(this.CheckedBtnArr));
    let ids = [];
    this.C_arr_data = [];
    this.T_data.forEach((ele) => {
      this.C_arr_data.push(ele["id"]);
    });
    // console.log("FFFFFFFFFFFFFFFFFFFF");
    // console.log(this.rowClone, this.pc, this.TreeSaveNode);
    // console.log("FFFFFFFFFFFFFFFFFFFF");
    // this.$refs.tree.setCheckedKeys(this.C_arr_data);
    this.groupId = this.rowClone["id"];
    this.menuId = this.TreeSaveNode["id"];
    this.getEchoFun();
  },
  watch:{
      C_arr_data:{
          handler(newValue,oldValue){
              console.log(newValue)
          },
          deep:true
      },
      CheckedBtnArr: {
      handler(newValue, oldValue) {
        this.T_data = JSON.parse(JSON.stringify(this.CheckedBtnArr));
        // console.log("FFFFFFFFFFFFFFFFFFFF");
        // console.log(this.rowClone, this.pc, this.TreeSaveNode);
        // console.log("FFFFFFFFFFFFFFFFFFFF");
        this.groupId = this.rowClone["id"];
        this.menuId = this.TreeSaveNode["id"];
        this.getEchoFun();
      },
      deep: true,
    },
  },
  methods:{
      //点击节点
      NodeClick(val){
          console.log(val)
      },
      //节点发生变化
      checkChange(val){
           this.checkChangeData.push(val)
            console.log(this.$refs.tree.getCheckedKeys())
            let arr=this.$refs.tree.getCheckedKeys()
           this.$emit('backBtnList',arr)
      },
       //获取回显
    getEchoFun() {
       this.$refs.tree.setCheckedKeys([]);
      elementEcho(this.groupId, this.menuId).then((Response) => {
        console.log(Response);
        let arrobj=Response.data;
        let keyArr=[];
        arrobj.forEach(ele=>{
          keyArr.push(ele['id'])
        })
        this.$refs.tree.setCheckedKeys(keyArr);
        console.log(keyArr)
        // this.$emit("backBtnList", keyArr);
      });
    },
  }
};
</script>
<style lang="scss">
// .oset{
//   border-top: 1px solid #cccccc;
// }
  .eltree{
  background: #F0F4FA;
}
</style>